package leetcode_acm.array;

import org.junit.Test;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月20日 20:36
 */
public class MinSubArrayLen {
    public int minSubArrayLen(int target, int[] nums) {
        if(nums == null || nums.length == 0){
            return 0;
        }
        int n = nums.length;
        int left = 0,right = 0,min = Integer.MAX_VALUE;
        long sum = 0;
        while(right < n){
            sum += nums[right++];
            while(sum >= target){
                min = Math.min(min,right - left);
                sum -= nums[left++];
            }
        }
        return min == Integer.MAX_VALUE?0:min;
    }

    @Test
    public void test(){
        System.out.println(minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 3}));
    }

}
